package ogs.game.utils;

import java.nio.CharBuffer;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

public class FlashPolicyHandler extends IoHandlerAdapter {
	private static final String POLICY_REQ = "<policy-file-request/>";
	private static final String POLICY_RESP = "<cross-domain-policy>" +
			"<allow-access-from domain=\"*\" to-ports=\"*\"/>" +
			"</cross-domain-policy>";

	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception {
		IoBuffer msg = (IoBuffer) message;
		CharBuffer buffer = msg.asCharBuffer();
		System.out.println(buffer);
		if (buffer.toString().equalsIgnoreCase(POLICY_REQ))
		{
			session.write(POLICY_RESP);
		}
		session.close(false);
	}

}
